package cn.darkhorse.mesadmin.controller.pick;

import java.util.List;


import cn.darkhorse.device.pojo.MesDevice;
import cn.darkhorse.device.service.MesDeviceService;
import cn.darkhorse.pick.pojo.PickInfo;
import cn.darkhorse.pick.service.IPickInfoService;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采摘信息Controller
 *
 * @author ruoyi
 * @date 2021-05-16
 */
@Api(tags = "采摘信息管理")
@RestController
@RequestMapping("/pick/PickInfo")
public class PickInfoController extends BaseController
{

    @Autowired
    private IPickInfoService pickInfoService;

    @Autowired
    private MesDeviceService deviceService;

    /**
     * 查询采摘信息列表
     */

    @ApiOperation(value = "获取采摘信息列表")
    @GetMapping("/list")
    public TableDataInfo list(PickInfo pickInfo)
    {
        startPage();
        List<PickInfo> list = pickInfoService.selectPickInfoList(pickInfo);
        return getDataTable(list);
    }

    /**
     * 导出采摘信息列表
     */

    @Log(title = "采摘信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PickInfo pickInfo)
    {
        List<PickInfo> list = pickInfoService.selectPickInfoList(pickInfo);
        ExcelUtil<PickInfo> util = new ExcelUtil<PickInfo>(PickInfo.class);
        return util.exportExcel(list, "PickInfo");
    }

    /**
     * 首页统计
     */
    @GetMapping("/app/index")
    public AjaxResult appIndex() {
        JSONObject data = new JSONObject();
//        今日棉包
        data.put("todayCottonBag", pickInfoService.lambdaQuery().like(PickInfo::getCreateTime, DateUtils.getDate()).count());
//        本年度棉包
        data.put("thisYearCottonBag", pickInfoService.lambdaQuery().like(PickInfo::getCreateTime, DateUtils.getYear()).count());

//        在线数量
        data.put("online",deviceService.lambdaQuery().eq(MesDevice::getDeviceOnline, 1).count());
//        离线数量
        data.put("offline",deviceService.lambdaQuery().eq(MesDevice::getDeviceOnline, 0).count());

        return AjaxResult.success(data);
    }
}
